package nc.impl.test2;

import nc.impl.pub.ace.AceGoodsPubServiceImpl;
import nc.impl.pubapp.pub.smart.BatchSaveAction;
import nc.itf.test2.IGoodsMaintain;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.bd.meta.BatchOperateVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.AppContext;
import nc.vo.test2.goods.GoodsVO;

import org.apache.commons.lang.ArrayUtils;

public class GoodsMaintainImpl extends AceGoodsPubServiceImpl
		implements IGoodsMaintain {

	@Override
	public GoodsVO[] query(IQueryScheme queryScheme) throws BusinessException {
		return super.pubquerybasedoc(queryScheme);
	}

	@Override
	public BatchOperateVO batchSave(BatchOperateVO batchVO) throws BusinessException {
		
		Object[] addVOs =  batchVO.getAddObjs();
		Object[] uptVOs =  batchVO.getUpdObjs();
		
		if(!ArrayUtils.isEmpty(addVOs)){
			for(Object obj : addVOs){
				GoodsVO temp = (GoodsVO) obj;
				
				temp.setAttributeValue("creator", AppContext.getInstance().getPkUser());
				temp.setAttributeValue("creationtime", AppContext.getInstance().getServerTime());
			}
		}
		
		if(!ArrayUtils.isEmpty(uptVOs)){
			for(Object obj : uptVOs){
				GoodsVO temp = (GoodsVO) obj;
				temp.setAttributeValue("modifier", AppContext.getInstance().getPkUser());
				temp.setAttributeValue("modifiedtime", AppContext.getInstance().getServerTime());
			}
		}
		
		BatchSaveAction<GoodsVO> saveAction = new BatchSaveAction<GoodsVO>();
		BatchOperateVO retData = saveAction.batchSave(batchVO);
		
		new nc.bs.test2.goods.ace.rule.UniqueCheckRule().process(new BatchOperateVO[]{ retData});
		
		
		
		
		
		return retData;
	}
}
